package sendmethodinterfacelogic

import (
	"context"
	"errors"

	"dfx_cmdb/cmdb-sendmsg-rpc/internal/svc"
	cmdb_database_sync "dfx_cmdb/cmdb-sendmsg-rpc/types/cmdb-database-sync"
	"dfx_cmdb/models"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteSendMethodLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDeleteSendMethodLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteSendMethodLogic {
	return &DeleteSendMethodLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// DeleteSendMethod 删除指定的发送方式配置
func (l *DeleteSendMethodLogic) DeleteSendMethod(in *cmdb_database_sync.DeleteRequest) (*cmdb_database_sync.PublicMsgResponse, error) {
	// todo: add your logic here and delete this line
	tx := l.svcCtx.DB

	err := models.DeleteDatabase(tx, in.IDs)
	if err != nil {
		return &cmdb_database_sync.PublicMsgResponse{
			Msg: "删除失败",
		}, errors.New("删除失败")
	}

	return &cmdb_database_sync.PublicMsgResponse{
		Msg: "删除成功",
	}, nil
}
